/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 *
 */

#ifndef __PQ_NetInputStream_H__
#define __PQ_NetInputStream_H__

#include "TCPSocket.h"

#define NET_INPUT_SIZE_DEFAULT	64*1024
#define NET_INPUT_SIZE_MAX			96*1024//disconnect when reach this limit

namespace PQNet
{
	/*
	This class is used to receive,store and format the network message.
	*/
	class NetInputStream
	{
	public:
		NetInputStream(PQNet::TCPSocket* sock,
			int bufferSize=NET_INPUT_SIZE_DEFAULT,
			int maxBufferSize=NET_INPUT_SIZE_MAX);

		virtual ~NetInputStream();

		int fill();

		void initBuffer();

		bool resize(int size);

		int length( ) const;
	protected:
		PQNet::TCPSocket* _socket;

		char* _buffer;
		int _bufferSize;
		int _maxBufferSize;

		int _head;
		int _tail;

	};

}

#endif


